import { createStore } from 'vuex';

export default createStore({
  state: {
    user: {
      avatar: localStorage.getItem('userAvatar') || ''  // 获取用户头像
    }
  },
  mutations: {
    updateUserAvatar(state, payload) {
      console.log('Mutation called with payload:', payload); // 调试信息
      state.user.avatar = payload;
    }
  },
  actions: {
    updateAvatar({ commit }, payload) {
      console.log('Action called with payload:', payload); // 调试信息
      commit('updateUserAvatar', payload);
    }
  },
  getters: {
    getUserAvatar: (state) => state.user.avatar
  }
});